import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hc24.util.IDUtil;
import com.hc24.util.db.ResultCallBack;
import com.hc24.util.db.SqlTemplate;
import com.mef.smsplat.dao.AirportInfoDao;
import com.mef.smsplat.domain.AirportInfoDomain;

/**
 * 机场数据导入
 * @author hc24
 *
 */
public class ImpAirportData {
	
	public static void imp(){
		ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
		final AirportInfoDao airportInfoDao=(AirportInfoDao) context.getBean("airportInfoDao");
		
		//从Oracle数据库中得到数据
		SqlTemplate sqlTemplate=new SqlTemplate("select * from xz_airport");
		sqlTemplate.execute(new ResultCallBack() {
			
			public Object export(ResultSet rs) throws SQLException {
				int i=0;
				int j=0;
				while(rs.next()){
					AirportInfoDomain domain=new AirportInfoDomain();
					domain.setAirportId(IDUtil.next()+"");
					domain.setAirportName(rs.getString("AIRPORT_NAME"));
					domain.setChName(rs.getString("CHNAME"));
					domain.setEnName(rs.getString("ENGNAME"));
					domain.setCode(rs.getString("THREEZCODE"));
					try{
						airportInfoDao.save(domain);//保存
						i++;
					}catch(Exception e){
						j++;
					}
					
				}
				System.out.println("数据导入完成，成功:"+i+"条；失败"+j+"条");
				return null;
			}
		});
	}
	
	public static void main(String[] args) {
		imp();
	}
	
}
